<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - ged.info - test/execution_monitor.hpp</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LTP GCOV extension - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
        <tr>
          <td class="headerItem" width="20%">Current&nbsp;view:</td>
          <td class="headerValue" width="80%" colspan=4><a href="../index.html">directory</a> - <a href="index.html">test</a> - execution_monitor.hpp</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Test:</td>
          <td class="headerValue" width="80%" colspan=4>ged.info</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Date:</td>
          <td class="headerValue" width="20%">2009-06-09</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Instrumented&nbsp;lines:</td>
          <td class="headerValue" width="20%">8</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Code&nbsp;covered:</td>
          <td class="headerValue" width="20%">50.0 %</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Executed&nbsp;lines:</td>
          <td class="headerValue" width="20%">4</td>
        </tr>
        </table>
      </td>
    </tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td><pre class="source">
<span class="lineNum">       1 </span>                : //  (C) Copyright Gennadiy Rozental 2001-2008.
<span class="lineNum">       2 </span>                : //  (C) Copyright Beman Dawes 2001.
<span class="lineNum">       3 </span>                : //  Distributed under the Boost Software License, Version 1.0.
<span class="lineNum">       4 </span>                : //  (See accompanying file LICENSE_1_0.txt or copy at 
<span class="lineNum">       5 </span>                : //  http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">       6 </span>                : 
<span class="lineNum">       7 </span>                : //  See http://www.boost.org/libs/test for the library home page.
<span class="lineNum">       8 </span>                : //
<span class="lineNum">       9 </span>                : //  File        : $RCSfile$
<span class="lineNum">      10 </span>                : //
<span class="lineNum">      11 </span>                : //  Version     : $Revision: 49312 $
<span class="lineNum">      12 </span>                : //
<span class="lineNum">      13 </span>                : //  Description : defines abstract monitor interfaces and implements execution exception
<span class="lineNum">      14 </span>                : //  The original Boost Test Library included an implementation detail function
<span class="lineNum">      15 </span>                : //  named catch_exceptions() which caught otherwise uncaught C++ exceptions.
<span class="lineNum">      16 </span>                : //  It was derived from an existing test framework by Beman Dawes.  The
<span class="lineNum">      17 </span>                : //  intent was to expand later to catch other detectable but platform dependent
<span class="lineNum">      18 </span>                : //  error events like Unix signals or Windows structured C exceptions.
<span class="lineNum">      19 </span>                : //
<span class="lineNum">      20 </span>                : //  Requests from early adopters of the Boost Test Library included
<span class="lineNum">      21 </span>                : //  configurable levels of error message detail, elimination of templates,
<span class="lineNum">      22 </span>                : //  separation of error reporting, and making the catch_exceptions() facilities
<span class="lineNum">      23 </span>                : //  available as a public interface.  Support for unit testing also stretched
<span class="lineNum">      24 </span>                : //  the function based design.  Implementation within the header became less
<span class="lineNum">      25 </span>                : //  attractive due to the need to include many huge system dependent headers,
<span class="lineNum">      26 </span>                : //  although still preferable in certain cases.
<span class="lineNum">      27 </span>                : //
<span class="lineNum">      28 </span>                : //  All those issues have been addressed by introducing the class-based
<span class="lineNum">      29 </span>                : //  design presented here.
<span class="lineNum">      30 </span>                : // ***************************************************************************
<span class="lineNum">      31 </span>                : 
<span class="lineNum">      32 </span>                : #ifndef BOOST_TEST_EXECUTION_MONITOR_HPP_071894GER
<span class="lineNum">      33 </span>                : #define BOOST_TEST_EXECUTION_MONITOR_HPP_071894GER
<span class="lineNum">      34 </span>                : 
<span class="lineNum">      35 </span>                : // Boost.Test
<span class="lineNum">      36 </span>                : #include &lt;boost/test/detail/global_typedef.hpp&gt;
<span class="lineNum">      37 </span>                : #include &lt;boost/test/detail/fwd_decl.hpp&gt;
<span class="lineNum">      38 </span>                : #include &lt;boost/test/utils/callback.hpp&gt;
<span class="lineNum">      39 </span>                : #include &lt;boost/test/utils/class_properties.hpp&gt;
<span class="lineNum">      40 </span>                : 
<span class="lineNum">      41 </span>                : // Boost
<span class="lineNum">      42 </span>                : #include &lt;boost/scoped_ptr.hpp&gt;
<span class="lineNum">      43 </span>                : #include &lt;boost/scoped_array.hpp&gt;
<span class="lineNum">      44 </span>                : #include &lt;boost/type.hpp&gt;
<span class="lineNum">      45 </span>                : #include &lt;boost/cstdlib.hpp&gt;
<span class="lineNum">      46 </span>                : 
<span class="lineNum">      47 </span>                : #include &lt;boost/test/detail/suppress_warnings.hpp&gt;
<span class="lineNum">      48 </span>                : 
<span class="lineNum">      49 </span>                : //____________________________________________________________________________//
<span class="lineNum">      50 </span>                : 
<span class="lineNum">      51 </span>                : namespace boost {
<span class="lineNum">      52 </span>                : 
<span class="lineNum">      53 </span>                : namespace detail {
<span class="lineNum">      54 </span>                : 
<span class="lineNum">      55 </span>                : // ************************************************************************** //
<span class="lineNum">      56 </span>                : // **************       detail::translate_exception_base       ************** //
<span class="lineNum">      57 </span>                : // ************************************************************************** //
<span class="lineNum">      58 </span>                : 
<span class="lineNum">      59 </span>                : class BOOST_TEST_DECL translate_exception_base {
<span class="lineNum">      60 </span>                : public:
<span class="lineNum">      61 </span>                :     // Constructor
<span class="lineNum">      62 </span>                :     explicit    translate_exception_base( boost::scoped_ptr&lt;translate_exception_base&gt;&amp; next )
<span class="lineNum">      63 </span>                :     {
<span class="lineNum">      64 </span>                :         next.swap( m_next );
<span class="lineNum">      65 </span>                :     }
<span class="lineNum">      66 </span>                : 
<span class="lineNum">      67 </span>                :     // Destructor
<span class="lineNum">      68 </span>                :     virtual     ~translate_exception_base() {}
<span class="lineNum">      69 </span>                : 
<span class="lineNum">      70 </span>                :     virtual int operator()( unit_test::callback0&lt;int&gt; const&amp; F ) = 0;
<span class="lineNum">      71 </span>                : 
<span class="lineNum">      72 </span>                : protected:
<span class="lineNum">      73 </span>                :     // Data members
<span class="lineNum">      74 </span>                :     boost::scoped_ptr&lt;translate_exception_base&gt; m_next;
<span class="lineNum">      75 </span>                : };
<span class="lineNum">      76 </span>                : 
<span class="lineNum">      77 </span>                : } // namespace detail
<span class="lineNum">      78 </span>                : 
<span class="lineNum">      79 </span>                : // ************************************************************************** //
<span class="lineNum">      80 </span>                : // **************              execution_exception             ************** //
<span class="lineNum">      81 </span>                : // ************************************************************************** //
<span class="lineNum">      82 </span>                :     
<span class="lineNum">      83 </span>                : //  design rationale: fear of being out (or nearly out) of memory.
<span class="lineNum">      84 </span>                :     
<span class="lineNum">      85 </span>                : class BOOST_TEST_DECL execution_exception {
<span class="lineNum">      86 </span>                :     typedef boost::unit_test::const_string const_string;
<span class="lineNum">      87 </span>                : public:
<span class="lineNum">      88 </span>                :     enum error_code {
<span class="lineNum">      89 </span>                :         //  These values are sometimes used as program return codes.
<span class="lineNum">      90 </span>                :         //  The particular values have been chosen to avoid conflicts with
<span class="lineNum">      91 </span>                :         //  commonly used program return codes: values &lt; 100 are often user
<span class="lineNum">      92 </span>                :         //  assigned, values &gt; 255 are sometimes used to report system errors.
<span class="lineNum">      93 </span>                :         //  Gaps in values allow for orderly expansion.
<span class="lineNum">      94 </span>                :         
<span class="lineNum">      95 </span>                :         no_error               = 0,   // for completeness only; never returned
<span class="lineNum">      96 </span>                :         user_error             = 200, // user reported non-fatal error
<span class="lineNum">      97 </span>                :         cpp_exception_error    = 205, // see note (1) below
<span class="lineNum">      98 </span>                :         system_error           = 210, // see note (2) below
<span class="lineNum">      99 </span>                :         timeout_error          = 215, // only detectable on certain platforms
<span class="lineNum">     100 </span>                :         user_fatal_error       = 220, // user reported fatal error
<span class="lineNum">     101 </span>                :         system_fatal_error     = 225  // see note (2) below
<span class="lineNum">     102 </span>                :         
<span class="lineNum">     103 </span>                :         //  Note 1: Only uncaught C++ exceptions are treated as errors.
<span class="lineNum">     104 </span>                :         //  If the application catches a C++ exception, it will never reach
<span class="lineNum">     105 </span>                :         //  the execution_monitor.
<span class="lineNum">     106 </span>                :         
<span class="lineNum">     107 </span>                :         //  Note 2: These errors include Unix signals and Windows structured
<span class="lineNum">     108 </span>                :         //  exceptions.  They are often initiated by hardware traps.
<span class="lineNum">     109 </span>                :         //
<span class="lineNum">     110 </span>                :         //  The implementation decides what is a fatal_system_exception and what is
<span class="lineNum">     111 </span>                :         //  just a system_exception.  Fatal errors are so likely to have corrupted
<span class="lineNum">     112 </span>                :         //  machine state (like a stack overflow or addressing exception) that it
<span class="lineNum">     113 </span>                :         //  is unreasonable to continue execution.
<span class="lineNum">     114 </span>                :     };
<span class="lineNum">     115 </span>                :     
<span class="lineNum">     116 </span>                :     // Constructor
<span class="lineNum">     117 </span><span class="lineNoCov">              0 :     execution_exception( error_code ec_, const_string what_msg_ ) // max length 256 inc '\0'</span>
<span class="lineNum">     118 </span><span class="lineNoCov">              0 :     : m_error_code( ec_ ), m_what( what_msg_ ) {}</span>
<span class="lineNum">     119 </span>                : 
<span class="lineNum">     120 </span>                :     // access methods
<span class="lineNum">     121 </span><span class="lineNoCov">              0 :     error_code      code() const { return m_error_code; }</span>
<span class="lineNum">     122 </span><span class="lineNoCov">              0 :     const_string    what() const { return m_what; }</span>
<span class="lineNum">     123 </span>                : 
<span class="lineNum">     124 </span>                : private:
<span class="lineNum">     125 </span>                :     // Data members
<span class="lineNum">     126 </span>                :     error_code      m_error_code;
<span class="lineNum">     127 </span>                :     const_string    m_what;
<span class="lineNum">     128 </span>                : }; // execution_exception
<span class="lineNum">     129 </span>                : 
<span class="lineNum">     130 </span>                : // ************************************************************************** //
<span class="lineNum">     131 </span>                : // **************               execution_monitor              ************** //
<span class="lineNum">     132 </span>                : // ************************************************************************** //
<span class="lineNum">     133 </span>                : 
<span class="lineNum">     134 </span><span class="lineCov">              6 : class BOOST_TEST_DECL execution_monitor {</span>
<span class="lineNum">     135 </span>                : public:
<span class="lineNum">     136 </span>                :     // Constructor
<span class="lineNum">     137 </span><span class="lineCov">              6 :     execution_monitor()</span>
<span class="lineNum">     138 </span>                :     : p_catch_system_errors( true )
<span class="lineNum">     139 </span>                :     , p_auto_start_dbg( false )
<span class="lineNum">     140 </span>                :     , p_timeout( 0 )
<span class="lineNum">     141 </span>                :     , p_use_alt_stack( true )
<span class="lineNum">     142 </span><span class="lineCov">              6 :     , p_detect_fp_exceptions( false )</span>
<span class="lineNum">     143 </span><span class="lineCov">              6 :     {}</span>
<span class="lineNum">     144 </span>                : 
<span class="lineNum">     145 </span>                :     // Public properties
<span class="lineNum">     146 </span>                :     
<span class="lineNum">     147 </span>                :     //  The p_catch_system_errors parameter specifies whether the monitor should 
<span class="lineNum">     148 </span>                :     //  try to catch system errors/exceptions that would cause program to crash 
<span class="lineNum">     149 </span>                :     //  in regular case
<span class="lineNum">     150 </span>                :     unit_test::readwrite_property&lt;bool&gt; p_catch_system_errors; 
<span class="lineNum">     151 </span>                :     //  The p_auto_start_dbg parameter specifies whether the monitor should 
<span class="lineNum">     152 </span>                :     //  try to attach debugger in case of caught system error
<span class="lineNum">     153 </span>                :     unit_test::readwrite_property&lt;bool&gt; p_auto_start_dbg;
<span class="lineNum">     154 </span>                :     //  The p_timeout parameter specifies the seconds that elapse before
<span class="lineNum">     155 </span>                :     //  a timer_error occurs.  May be ignored on some platforms.
<span class="lineNum">     156 </span>                :     unit_test::readwrite_property&lt;int&gt;  p_timeout;
<span class="lineNum">     157 </span>                :     //  The p_use_alt_stack parameter specifies whether the monitor should
<span class="lineNum">     158 </span>                :     //  use alternative stack for the signal catching
<span class="lineNum">     159 </span>                :     unit_test::readwrite_property&lt;bool&gt; p_use_alt_stack;
<span class="lineNum">     160 </span>                :     //  The p_detect_fp_exceptions parameter specifies whether the monitor should
<span class="lineNum">     161 </span>                :     //  try to detect hardware floating point exceptions
<span class="lineNum">     162 </span>                :     unit_test::readwrite_property&lt;bool&gt; p_detect_fp_exceptions;
<span class="lineNum">     163 </span>                : 
<span class="lineNum">     164 </span>                :     int         execute( unit_test::callback0&lt;int&gt; const&amp; F ); 
<span class="lineNum">     165 </span>                :     //  Returns:  Value returned by function call F().
<span class="lineNum">     166 </span>                :     //
<span class="lineNum">     167 </span>                :     //  Effects:  Calls executes supplied function F inside a try/catch block which also may
<span class="lineNum">     168 </span>                :     //  include other unspecified platform dependent error detection code.
<span class="lineNum">     169 </span>                :     //
<span class="lineNum">     170 </span>                :     //  Throws: execution_exception on an uncaught C++ exception,
<span class="lineNum">     171 </span>                :     //  a hardware or software signal, trap, or other exception.
<span class="lineNum">     172 </span>                :     //
<span class="lineNum">     173 </span>                :     //  Note: execute() doesn't consider it an error for F to return a non-zero value.
<span class="lineNum">     174 </span>                :     
<span class="lineNum">     175 </span>                :     // register custom (user supplied) exception translator
<span class="lineNum">     176 </span>                :     template&lt;typename Exception, typename ExceptionTranslator&gt;
<span class="lineNum">     177 </span>                :     void        register_exception_translator( ExceptionTranslator const&amp; tr, boost::type&lt;Exception&gt;* = 0 );
<span class="lineNum">     178 </span>                : 
<span class="lineNum">     179 </span>                : private:
<span class="lineNum">     180 </span>                :     // implementation helpers
<span class="lineNum">     181 </span>                :     int         catch_signals( unit_test::callback0&lt;int&gt; const&amp; F );
<span class="lineNum">     182 </span>                : 
<span class="lineNum">     183 </span>                :     // Data members
<span class="lineNum">     184 </span>                :     boost::scoped_ptr&lt;detail::translate_exception_base&gt; m_custom_translators;
<span class="lineNum">     185 </span>                :     boost::scoped_array&lt;char&gt;                           m_alt_stack;
<span class="lineNum">     186 </span>                : }; // execution_monitor
<span class="lineNum">     187 </span>                : 
<span class="lineNum">     188 </span>                : namespace detail {
<span class="lineNum">     189 </span>                : 
<span class="lineNum">     190 </span>                : // ************************************************************************** //
<span class="lineNum">     191 </span>                : // **************         detail::translate_exception          ************** //
<span class="lineNum">     192 </span>                : // ************************************************************************** //
<span class="lineNum">     193 </span>                : 
<span class="lineNum">     194 </span>                : template&lt;typename Exception, typename ExceptionTranslator&gt;
<span class="lineNum">     195 </span>                : class translate_exception : public translate_exception_base
<span class="lineNum">     196 </span>                : {
<span class="lineNum">     197 </span>                :     typedef boost::scoped_ptr&lt;translate_exception_base&gt; base_ptr;
<span class="lineNum">     198 </span>                : public:
<span class="lineNum">     199 </span>                :     explicit    translate_exception( ExceptionTranslator const&amp; tr, base_ptr&amp; next )
<span class="lineNum">     200 </span>                :     : translate_exception_base( next ), m_translator( tr ) {}
<span class="lineNum">     201 </span>                : 
<span class="lineNum">     202 </span>                :     int operator()( unit_test::callback0&lt;int&gt; const&amp; F )
<span class="lineNum">     203 </span>                :     {
<span class="lineNum">     204 </span>                :         try {
<span class="lineNum">     205 </span>                :             return m_next ? (*m_next)( F ) : F();
<span class="lineNum">     206 </span>                :         } catch( Exception const&amp; e ) {
<span class="lineNum">     207 </span>                :             m_translator( e );
<span class="lineNum">     208 </span>                :             return boost::exit_exception_failure;
<span class="lineNum">     209 </span>                :         }
<span class="lineNum">     210 </span>                :     }
<span class="lineNum">     211 </span>                : 
<span class="lineNum">     212 </span>                : private:
<span class="lineNum">     213 </span>                :     // Data members
<span class="lineNum">     214 </span>                :     ExceptionTranslator m_translator;
<span class="lineNum">     215 </span>                : };
<span class="lineNum">     216 </span>                : 
<span class="lineNum">     217 </span>                : } // namespace detail
<span class="lineNum">     218 </span>                : 
<span class="lineNum">     219 </span>                : template&lt;typename Exception, typename ExceptionTranslator&gt;
<span class="lineNum">     220 </span>                : void
<span class="lineNum">     221 </span>                : execution_monitor::register_exception_translator( ExceptionTranslator const&amp; tr, boost::type&lt;Exception&gt;* )
<span class="lineNum">     222 </span>                : {
<span class="lineNum">     223 </span>                :     m_custom_translators.reset( 
<span class="lineNum">     224 </span>                :         new detail::translate_exception&lt;Exception,ExceptionTranslator&gt;( tr,m_custom_translators ) );
<span class="lineNum">     225 </span>                : }
<span class="lineNum">     226 </span>                : 
<span class="lineNum">     227 </span>                : // ************************************************************************** //
<span class="lineNum">     228 </span>                : // **************               execution_aborted              ************** //
<span class="lineNum">     229 </span>                : // ************************************************************************** //
<span class="lineNum">     230 </span>                : 
<span class="lineNum">     231 </span>                : struct execution_aborted {};
<span class="lineNum">     232 </span>                : 
<span class="lineNum">     233 </span>                : // ************************************************************************** //
<span class="lineNum">     234 </span>                : // **************                  system_error                ************** //
<span class="lineNum">     235 </span>                : // ************************************************************************** //
<span class="lineNum">     236 </span>                : 
<span class="lineNum">     237 </span>                : class system_error {
<span class="lineNum">     238 </span>                : public:
<span class="lineNum">     239 </span>                :     // Constructor
<span class="lineNum">     240 </span>                :     explicit    system_error( char const* exp );
<span class="lineNum">     241 </span>                : 
<span class="lineNum">     242 </span>                :     unit_test::readonly_property&lt;long&gt;          p_errno; 
<span class="lineNum">     243 </span>                :     unit_test::readonly_property&lt;char const*&gt;   p_failed_exp; 
<span class="lineNum">     244 </span>                : };
<span class="lineNum">     245 </span>                : 
<span class="lineNum">     246 </span>                : #define BOOST_TEST_SYS_ASSERT( exp ) if( (exp) ) ; else throw ::boost::system_error( BOOST_STRINGIZE( exp ) )
<span class="lineNum">     247 </span>                : 
<span class="lineNum">     248 </span>                : }  // namespace boost
<span class="lineNum">     249 </span>                : 
<span class="lineNum">     250 </span>                : //____________________________________________________________________________//
<span class="lineNum">     251 </span>                : 
<span class="lineNum">     252 </span>                : #include &lt;boost/test/detail/enable_warnings.hpp&gt;
<span class="lineNum">     253 </span>                : 
<span class="lineNum">     254 </span>                : #endif
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
  <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LTP GCOV extension version 1.6</a></td></tr>
  </table>
  <br>

</body>
</html>
